<template>
	<view></view>
</template>

<script setup lang="ts">
	import { onLoad } from '@dcloudio/uni-app'
	import { useUserStoreToRefs } from '@/store/useUserStore'
	import api from '@/api'
	const { shareRefereeId, shareStudioId } = useUserStoreToRefs()
	onLoad(async (params) => {
		console.log(params, '分享携带参数')
		uni.showLoading({
			mask: true,
			title: "加载中"
		})

		if (params.q) {
			let obj : any = {}
			// #ifdef MP-TOUTIAO
			obj = JSON.parse(params.q)
			// #endif
			// #ifdef MP-WEIXIN
			let arr1 = decodeURIComponent(params.q).split('?')[1].split('&')
			arr1.forEach(item => {
				let arr3 = item.split('=')
				obj[arr3[0]] = arr3[1]
			})
			// #endif
			//obj获取分享链接上携带的路由参数
			console.log(obj)
			shareRefereeId.value = obj.shareRefereeId
			if (shareRefereeId.value) {
				const res : any = await api({
					method: 'get',
					url: `/mall/studio/petsitter-team/getDetailByUserId?userId=${obj.shareRefereeId}`
				})
				console.log(res, "resresres")
				if (res.data && res.data.joinedStudioId) {
					shareStudioId.value = res.data.joinedStudioId
				}
			}


			setTimeout(() => {
				uni.hideLoading()
				let url = ""
				if (obj.type == 12) { //商城
					url = `/pages/onlineMall/index`
				}else if (obj.type == 11) { //商学院 
					url = `/pages/businessSchool/index/index`
				}else if (obj.type == 10) { //商品详情
					url = `/pages/shopping/productDetails/index?goodsId=${obj.goodsId}`
				}else if (obj.type == 9) { //店铺分享
					url = `/pages/shopping/shop/index?brands=${obj.data1}`
				}else if (obj.type == 8) { //考试详情
					url = `/pages/businessSchool/examDetails/index?courseId=${obj.id}`
				}else if (obj.type == 7) { //章节详情分享
					url = `/pages/businessSchool/chapterDetails/chapterDetails?courseId=${obj.data1}&chapterId=${obj.data2}`
				} else if (obj.type == 6) { //课程详情分享
					url = `/pages/businessSchool/courseDetails/courseDetails?courseId=${obj.data1}`
				} else if (obj.type == 5) { //服务详情
					url = `/pages/serviceDetails/details/index?studioGoodsId=${obj.data1}&studioId=${obj.studioId}`
				} else if (obj.type == 4) { //陪宠师首页
					url = `/pages/studio/petCompanionTeacherIndex/index?userId=${obj.data1}&studioId=${obj.data2}`
				} else if (obj.type == 3) { //工作室首页->首页
					url = `/pages/studio/index/index?id=${obj.data1}`
				} else if (obj.type == 2) { //系统首页
					url = `/pages/home/index?shareStoreId=${shareStudioId.value || ''}`
				} else if (obj.type == 1) { //跳转到申请陪宠师页面
					url = `/pages/applyPetTeacher/index/index?id=${obj.data1}`
				} 
				uni.reLaunch({
					url: url
				})
			}, 1500)

		}



	})
</script>

<style lang="scss" scoped>
</style>